package org.box.metadata.shell.web.ws.cs;

import java.util.Map;
import java.util.TreeMap;

import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;

import org.box.metadata.shell.WebConsoleModule.ServerOutStream;

import com.sun.jersey.spi.resource.Singleton;

@Path("log")
@Singleton
public class ServerLogService {
	
	public static Map<String, String> orders = new TreeMap<String, String>();
	private ServerOutStream stream;

	@Path("/{order}")
	@PUT
	@Produces("text/html")
	public String create(@PathParam("order") String order,
			@QueryParam("customer_name") String customerName) {
		orders.put(order, customerName);
		return "Added order #" + order;
	}

	@Path("/{order}")
	@GET
	@Produces("text/html")
	public String find(@PathParam("order") String order) {
		if (orders.containsKey(order))
			return "<h2>Details on Order #" + order + "</h2><p>Customer name: "
					+ orders.get(order);

		throw new WebApplicationException();
	}

	@Path("/list")
	@GET
	@Produces("text/html")
	public String list() {
		
		String header = "<h2>All Orders</h2>\n: Stream: ";// + stream.size();

		header += "<ul>";
		for (Map.Entry<String, String> order : orders.entrySet())
			header += "\n<li>#" + order.getKey() + " for " + order.getValue()
					+ "</li>";

		header += "\n</ul>";

		return header;
	}

}
